package tests;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;

public class ReceiverNode extends Agent {
	
	private String[] neigh = new String[1];
	
	private int count = 0;
	
	protected void setup()
	{
		try
		{
			Object[] args = getArguments();
			neigh[0] = (String) args[0];
			receiveMessage();
			
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	private void receiveMessage()
	{
		addBehaviour(new Behaviour() {
			
			public void action()
			{
				ACLMessage msg = Q.getInstance().receive(myAgent);
				
				if (msg != null)
				{
					Registry.getInstance().add(count+"", msg);
					count++;
				}
			}
			
			public boolean done()
			{
				return count == 100;
			}
		});
	}
	
}

